package com.example.padtestproject;

import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MusicDisplayActivity extends AppCompatActivity {

    private RecyclerView topChartsRecycler;
    private RecyclerView genresRecyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_music_display);

        // 初始化 RecyclerViews
        initTopChartsRecycler();
        initGenresRecycler();
    }

    /**
     * 初始化 Top Charts RecyclerView
     */
    private void initTopChartsRecycler() {
        topChartsRecycler = findViewById(R.id.topChartsRecycler);
        topChartsRecycler.setLayoutManager(new LinearLayoutManager(this));

        // 设置 Top Charts 数据
        List<Song> songList = getTopChartsData();
        SongAdapter adapter = new SongAdapter(songList, song -> {
            // 处理点击事件
            // ...
            Intent intent = new Intent(MusicDisplayActivity.this, MainActivity.class);
            intent.putExtra("songName", song.getName());
            startActivity(intent);
        });
        topChartsRecycler.setAdapter(adapter);
    }

    /**
     * 初始化 Genres RecyclerView
     */
    private void initGenresRecycler() {
        genresRecyclerView = findViewById(R.id.genresRecyclerView);
        genresRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));

        // 设置 Genres 数据
        List<Genre> genres = getGenresData();
        GenreAdapter genreAdapter = new GenreAdapter(genres);
        genresRecyclerView.setAdapter(genreAdapter);
    }

    /**
     * 获取 Top Charts 数据
     * @return List<Song>
     */
    private List<Song> getTopChartsData() {
        List<Song> songList = new ArrayList<>();
        songList.add(new Song("So Am I", "Ava Max", "02:47"));
        songList.add(new Song("Dancing with My Phone", "Jarryd James", "03:29"));
        songList.add(new Song("Six Feet Under", "Billie Eilish", "02:35"));
        return songList;
    }

    /**
     * 获取 Genres 数据
     * @return List<Genre>
     */
    private List<Genre> getGenresData() {
        List<Genre> genres = new ArrayList<>();
        genres.add(new Genre("Pop", R.drawable.genre_placeholder));
        genres.add(new Genre("Rock", R.drawable.genre_placeholder));
        genres.add(new Genre("Jazz", R.drawable.genre_placeholder));
        genres.add(new Genre("Hip-Hop", R.drawable.genre_placeholder));
        genres.add(new Genre("Classical", R.drawable.genre_placeholder));
        return genres;
    }
}